<?php
/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2019/10/23
 * Time: 12:05
 */
class Solution_01
{

    /**
     * @param String $s
     * @return Integer
     */
    function lengthOfLongestSubstring($s) {
        $start = $end = 0;
        $hash =[];
        $length = strlen($s);
        $max=0;
        for(;$end <$length;$end++){
            if(isset($hash[$s[$end]])){
                $start = max($hash[$s[$end]],$start);
            }
            $hash[$s[$end]] = $end +1;
            $max= max($end-$start+1,$max);
            if($max >= ($length-$start+1)) break;
        }
        return $max;
    }

}

$solution = new Solution_01();
echo $solution->lengthOfLongestSubstring("aabaaed");